<?php
namespace App\Http\Controllers\Admin;

use App\Models\Sys_Menu;
use App\Models\Sys_Role;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class MenuController extends Controller
{
    /**
     * 菜单列表
     * Author :fankexin
     * return  =>json
     */
    public function menuList(Request $request)
    {
//        $roleid = $request->input('roleid');
//        $info = Sys_Role::find($roleid);
//        $list = Sys_Menu::whereIn('id',json_decode($info->menu_ids,true))
//                ->orderBy('order','asc')
//                ->get()
//                ->toArray();
        $list = Sys_Menu::orderBy('order','asc')
            ->get()
            ->toArray();
        $arr = $this->getChild($list);
        return $this->responseSuccess(['list' => $arr]);
    }

    public function getMenuList(Request $request)
    {
        $roleid = $request->input('roleid');
        $info = Sys_Role::find($roleid);
//        $list = Sys_Menu::whereIn('id',json_decode($info->menu_ids,true))
//            ->pluck('menu_route');
////        $arr = $this->getChild($list);
        return $this->responseSuccess(['list' => json_decode($info->menu_ids,true)]);
    }
}
